package com.dongdongshop.service.impl;

import com.dongdongshop.mapper.TbTypeTemplateMapper;
import com.dongdongshop.pojo.PageResult;
import com.dongdongshop.pojo.TbTypeTemplate;
import com.dongdongshop.pojo.TbTypeTemplateExample;
import com.dongdongshop.service.TbTypeTemplateService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DubboService
public class TbTypeTemplateServiceImpl implements TbTypeTemplateService {

    //注入mapper
    @Autowired
    private TbTypeTemplateMapper tbTypeTemplateMapper;

    //查询商品类型模板全部数据(要求分页)
    @Override
    public PageResult<TbTypeTemplate> TbTypeTemplateshowall(Integer pageNum, Integer pageSize, String name) {
        PageHelper.startPage(pageNum, pageSize);
        List<TbTypeTemplate> tbTypeTemplates = null;
        if ("".equals(name) || name == null) {
            tbTypeTemplates = tbTypeTemplateMapper.selectByExample(null);
        } else {
            TbTypeTemplateExample te = new TbTypeTemplateExample();
            TbTypeTemplateExample.Criteria criteria = te.createCriteria();
            criteria.andNameLike("%" + name + "%");
            tbTypeTemplates = tbTypeTemplateMapper.selectByExample(te);
        }
        PageInfo<TbTypeTemplate> info = new PageInfo<>(tbTypeTemplates);
        return new PageResult<>(pageNum, pageSize, info.getTotal(), info.getList(), info.getPages());
    }

    //添加商品类型模板
    @Override
    public void addTbTypeTemplate(TbTypeTemplate tbTypeTemplate) {
        tbTypeTemplateMapper.insertSelective(tbTypeTemplate);
    }

    //回显单个商品类型模板
    @Override
    public TbTypeTemplate showecho(Long id) {
        return tbTypeTemplateMapper.selectByPrimaryKey(id);
    }

    //修改商品类型模板数据
    @Override
    public void updateTbTypeTemplate(TbTypeTemplate tbTypeTemplate) {
        tbTypeTemplateMapper.updateByPrimaryKeySelective(tbTypeTemplate);
    }

    //删除单个数据
    @Override
    public void deleteTbSpecification(Long id) {
        tbTypeTemplateMapper.deleteByPrimaryKey(id);
    }

    //删除多个数据
    @Override
    public void deleteallTbTypeTemplate(List<Long> ids) {
        TbTypeTemplateExample te = new TbTypeTemplateExample();
        TbTypeTemplateExample.Criteria criteria = te.createCriteria();
        criteria.andIdIn(ids);
        tbTypeTemplateMapper.deleteByExample(te);
    }

    //查询商品类型模板全部数据
    @Override
    public List<TbTypeTemplate> TbTypeTemplateshow() {
        return tbTypeTemplateMapper.selectByExample(null);
    }

    //查询单个商品类型模板
    @Override
    public TbTypeTemplate showbyid(Long id) {
        return tbTypeTemplateMapper.selectByPrimaryKey(id);
    }
}
